/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo360.mobilesafe.utils;

import java.io.InputStream;
import java.io.OutputStream;
import java.security.MessageDigest;

public final class IoStreamUtils {
    private static final String TAG = "FWL.IoStreamUtils";

    public static final int readFully(InputStream paramInputStream, byte[] paramArrayOfByte, int paramInt1,
            int paramInt2) {
        while (paramInt2 > 0) {
            int i = paramInputStream.read(paramArrayOfByte, paramInt1, paramInt2);
            if (i < 0)
                return paramInt1;
            paramInt1 += i;
            paramInt2 -= i;
        }
        return paramInt1;
    }

    public static final void closeSilently(InputStream paramInputStream) {
        if (paramInputStream == null)
            return;
        try {
            paramInputStream.close();
        } catch (Throwable localThrowable) {}
    }

    public static final void closeSilently(OutputStream paramOutputStream) {
        if (paramOutputStream == null)
            return;
        try {
            paramOutputStream.close();
        } catch (Throwable localThrowable) {}
    }

    public static final String readUTF8(InputStream paramInputStream) {
        StringBuilder localStringBuilder = new StringBuilder();
        byte[] arrayOfByte = new byte[4096];
        int i = 0;
        while ((i = paramInputStream.read(arrayOfByte)) >= 0) {
            if (i <= 0)
                continue;
            localStringBuilder.append(new String(arrayOfByte, 0, i, "UTF-8"));
        }
        return localStringBuilder.toString();
    }

    public static final byte[] readMD5(InputStream paramInputStream) {
        MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
        byte[] arrayOfByte = new byte[4096];
        int i = 0;
        while ((i = paramInputStream.read(arrayOfByte)) >= 0) {
            if (i <= 0)
                continue;
            localMessageDigest.update(arrayOfByte, 0, i);
        }
        return localMessageDigest.digest();
    }
}